import fetcher from "./Fetcher";
import {Page, Pageable} from "../utils/Page";
import {NumberIdAndName} from "../types/BasicModels";

export function findMonthlyMarketGuideSalarySummary(marketId:number,pageable:Pageable){
    return fetcher.get<Page<QueryMarketShoppingGuideSalaryDocumentGroupByMonthResponse>>(`markets/${marketId}/shoppingGuides/salaryDocuments/monthlySalarySummary`,pageable.toRequestParams())
}

export interface QueryMarketShoppingGuideSalaryDocumentGroupByMonthResponse {
    year: number;
    month: number;
    totalSalary: number;
}

export function previewMonthlyMarketShoppingGuideSalaryDocuments(marketId:number,year:number,month:number){
    return fetcher.get<PreviewMonthlySalaryDocumentsResponse>(`markets/${marketId}/shoppingGuides/salaryDocuments/previewMonthlySalaryDocuments`,{
        year,
        month
    })
}

export interface PreviewMonthlySalaryDocumentsResponse {
    employeeSalaries: PreviewMonthlySalaryDocumentsEmployeeSalaryResponse[];
    /**
     * 总工资
     */
    totalSalary: number;
    /**
     * 总销量
     */
    totalSale: number;
    ruleSalaries: PreviewMonthlySalaryDocumentsRuleSalaryResponse[];
}

export interface PreviewMonthlySalaryDocumentsRuleSalaryResponse {
    id:number
    name: string;
    note?: string;
    /**
     * 工资计算结果
     */
    salary: number;
}

export interface PreviewMonthlySalaryDocumentsEmployeeSalaryResponse {
    id: number;
    name: string;
    totalSalary: number;
    items: PreviewMonthlySalaryDocumentsEmployeeSalaryItemResponse[];
}

export interface PreviewMonthlySalaryDocumentsEmployeeSalaryItemResponse {
    salary: number;
    note?: string;
    name: string;
}

export function generateMarketShoppingGuideSalaryDocuments(marketId:number,year:number,month:number){
    return fetcher.post(`markets/${marketId}/shoppingGuides/salaryDocuments/generateMonthlySalaryDocuments`,{
        year,
        month
    })
}

export function findMonthlyMarketShoppingGuideSalaryDocumentGroupByEmployee(marketId:number,year:number,month:number){
    return fetcher.get<MonthlySalaryGroupByEmployeeResponse[]>(`markets/${marketId}/shoppingGuides/salaryDocuments/monthlySalaryGroupByEmployee`,{
        year,
        month
    })
}

export interface MonthlySalaryGroupByEmployeeResponse {
    id: number;
    employee: NumberIdAndName;  // 注意：已存在类型映射
    items: MonthlySalaryGroupByEmployeeItemResponse[];
    note?: string;
}

export interface MonthlySalaryGroupByEmployeeItemResponse {
    id: number;
    salary: number;
    name: string;
    note?: string;
}